package com.wipz.eoa.iphone.myworkmanagent.enterprise;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.wipz.eoa.iphone.BaseAction;
import com.wipz.eoa.iphone.IBaseService;
import com.wipz.eoa.iphone.util.UUIDHexGenerator;

public class EnterpriseAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private IBaseService baseService;
	private IEnterpriseService enterpriseService;
	public void setBaseService(IBaseService baseService) {
		this.baseService = baseService;
	}
	public IBaseService getBaseService() {
		return baseService;
	}
	public void setEnterpriseService(IEnterpriseService enterpriseService) {
		this.enterpriseService = enterpriseService;
	}
	public IEnterpriseService getEnterpriseService() {
		return enterpriseService;
	}
	//客户详情信息
	private Object detail;
	public void setDetail(Object detail) {
		this.detail = detail;
	}
	public Object getDetail() {
		return detail;
	}

	
	/**
	 * 客户信息维护列表
	 */
	@SuppressWarnings("unchecked")
	private List list;
	public void setList(List list) {
		this.list = list;
	}
	public List getList() {
		return list;
	}

	/**
	 *客户信息维护列表
	 * @return
	 * 2012-1-13 下午05:09:55
	 * @throws UnsupportedEncodingException 
	 */
	public String list() throws UnsupportedEncodingException {
		String enterprisename = this.getRequest().getParameter("enterprisename");
		try {
			String s = new String(enterprisename.getBytes("iso-8859-1"),"utf-8");
			enterprisename= java.net.URLDecoder.decode(s, "utf-8");
		} catch (UnsupportedEncodingException e) {
			return SUCCESS;
		}
		System.out.println(enterprisename);
		Map<String,String>	parms = new HashMap<String,String>();
		parms.put("enterprisename", enterprisename);
		list =baseService.queryList("enterprise.querylist", parms);
		System.out.println(list.size());
		return SUCCESS;
	}
	
	/**
	 * 添加客户信息
	 * @throws UnsupportedEncodingException
	 */
	public void add() throws UnsupportedEncodingException {
		Map<String,String> map = new HashMap<String,String>();
		String id = UUIDHexGenerator.getInstance().generate();
		System.out.println(id);
		map.put("ID", id);
		map.put("ENTERPRISENAME", "软通动力");
		map.put("PROPERTIES", "企业");
		map.put("ADDRESS", "上地中关村软件园9号楼");
		map.put("EMAIL", "isoftstone@12.com");
		map.put("OFFICEPHONE", "12345678");
		map.put("DESCRIBE", "软通测试");
		map.put("LINKPERSON", "软通");
		enterpriseService.insertEnterprise(map);
	}
	
	/**
	 * 修改客户信息
	 * @throws UnsupportedEncodingException
	 */
	public void update() throws UnsupportedEncodingException {
		Map<String,String> map = new HashMap<String,String>();
		String id =  this.getRequest().getParameter("id");
		System.out.println(id);
		map.put("ID", id);
		enterpriseService.updateEnterprise(map);
	}
	/**
	 * 查询客户详情信息
	 * @return
	 * 2012-1-13 05:10:18
	 */
	public String detail() {
		String id = this.getRequest().getParameter("id");
		if(id.isEmpty()) {
			return SUCCESS;
		}
		if(StringUtils.isNotEmpty(id)){
			Map<String, String> params = new HashMap();
			params.put("id", id);
			detail=enterpriseService.queryOne("enterprise.queryById", params);
			//System.out.println(detail);
		}
		return SUCCESS;
	}
	
	/**
	 *删除客户信息维护
	 * @return
	 * 2012-1-13 下午05:09:55
	 * @throws UnsupportedEncodingException 
	 */
	public void delete() throws UnsupportedEncodingException {
		String id = this.getRequest().getParameter("id");
		getBaseService().delete("enterprise.delete", id);
	}


}
